<?php

namespace app\common\controller;

use app\common\library\Auth;
use think\Config;
use think\Controller;
use think\Hook;
use think\Lang;
use think\Db;
use think\Session;

/**
 * 前台控制器基类
 */
class Frontend extends Controller {

    /**
     * 布局模板
     * @var string
     */
    protected $layout = '';
    protected $iUserId = 0; //用户ID
    /**
     * 无需登录的方法,同时也就不需要鉴权了
     * @var array
     */
    protected $noNeedLogin = [];

    /**
     * 无需鉴权的方法,但需要登录
     * @var array
     */
    protected $noNeedRight = [];

    public function _initialize() {
        //自动处理已失效任务的订单
        $task_list = \think\Db::name('task')->where(array('task_status' => ['in', '5,6']))->select();

        foreach ($task_list as $val) {
            $data['order_status'] = 93;
            $data['updatetime'] = time();
            $res = \think\Db::name('order')->where(array('task_id' => $val['task_id']))->update($data);
        }
        
        $this->iUserId = Session('user_id');
        if (empty($this->iUserId) || $this->iUserId == 0) {
            $this->redirect('Pub/login');
        }
    }

}
